# encoding=utf-8

"""PyRenderPdf.py
    渲染html到pdf, 依赖https://wkhtmltopdf.org/downloads.html

    所以此模块完成自动下载安装, 以及转换的步骤
"""

import pdfkit


def convert_html_2_pdf(html_path: str, pdf_path: str, configs, options):
    pdfkit.from_file(html_path, pdf_path, configuration=configs, options=options)


if __name__ == '__main__':
    """
        wkhtmltopdf.exe --enable-local-file-access result.html result.pdf
    """

    pdf_exe = r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
    wkhtmltopdf_options = {
        'enable-local-file-access': None
    }
    config = pdfkit.configuration(wkhtmltopdf=pdf_exe)

    convert_html_2_pdf(
        "../HtmlTemplate/hospital_sample.html",
        "out1.pdf",
        config,
        wkhtmltopdf_options
    )
